package ch.nostromo.tiffanys.engines.tiffanys.ai;

import java.util.HashMap;

public class TranspositionTableTiff {

  private static final int HASH_SIZE = 100000;

  public static boolean full = false;
  private static HashMap<Long, Integer> boards = new HashMap<Long,Integer>(HASH_SIZE);
  public static int[] values = new int[HASH_SIZE];
  public static int[] depths = new int[HASH_SIZE];
  public static int[] modes = new int[HASH_SIZE];
  private static int counter = 0;

  public static int getBoardIdx(long board) {
    Integer idx = boards.get(new Long(board));
    
    if (idx != null) {
      return idx.intValue();
    }
    
    return 0;
  }

  public static void reset() {
    boards = new HashMap<Long, Integer>(HASH_SIZE);
    counter = 0;
  }
  
  public synchronized static void addBoard(long board, int value, int depth, int mode) {

    if (counter >= HASH_SIZE) {
      full = true;
      return;
    }

    boards.put(new Long(board), new Integer(counter));

    values[counter] = value;
    modes[counter] = mode;
    depths[counter] = depth;

    counter ++;
    
    return;
  }

}
